﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="UploadImage.aspx.cs" Inherits="ZLCMS.Web.Wap.Example.UploadImage" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta name="viewport" content="width=device-width,height=device-height,inital-scale=1.0,maximum-scale=1.0,user-scalable=no;">
    <title></title>
    <link rel="stylesheet" href="/wap/lib/jquerymobile/css/jquery.mobile-1.4.0.min.css" />
    <link rel="stylesheet" href="/wap/lib/validator-0.7.0/css/jquery.validator.css" />
    <script type="text/javascript" src="/wap/lib/jquery/jquery-1.10.2.min.js"></script>
    <script type="text/javascript" src="/wap/lib/jquerymobile/jquery.mobile-1.4.0.min.js"></script>
    <script type="text/javascript" src="/wap/lib/validator-0.7.0/jquery.validator.js"></script>
    <script type="text/javascript" src="/wap/lib/validator-0.7.0/local/zh_CN.js"></script>
    <script type="text/javascript" src="/wap/lib/jquery/jquery.json-2.2.min.js"></script>
    <script type="text/javascript" src="/wap/lib/command/Command.js"></script>
</head>
<body>
    <div data-role='page' id='mainPage'>
        <div data-role="header">
            <div class="logo">
            </div>
        </div>
        <div role="main" class="ui-content">
            <form id="formId" command='CommonWxApply'>
            <label for="text-basic">
                姓名:</label>
            <img width="100%" src="" id="uploadImg" />
            <button type="button" onclick="upload('uploadImg','PhotoUrl')">
                上传图片</button>
            <input type="hidden" id="PhotoUrl" />
            <button class="ui-btn" type="button" onclick="executeFormCommonCommand('formId', applyDone)">
                提交</button>
            <a id="showmessage" href="#dialogPage" style="display: none">#</a>
            </form>
        </div>
        <!--footer-->
        <div data-role="footer">
            <p>
                footer</p>
        </div>
    </div>
    <script src="/Wap/lib/command/Command.js" type="text/javascript"></script>
    <%=ZLCMS.Business.WeixinService.WeixinUtil.GetJsSdkConfig() %>
    <script src="/Wap/lib/jssdk.js" type="text/javascript"></script>
    <script type="text/javascript">
        function upload(imgId,valId) {
            var img = $('#' + imgId),valEl = $('#'+valId);
            wx.chooseImage({
                success: function (res) {
                    var localIds = res.localIds;
                    if(localIds)
                        img.attr("src", localIds[0]);
                        wx.uploadImage({
                            localId: localIds[0], 
                            isShowProgressTips: 1,
                            success: function (res) {
                                var serverId = res.serverId;
                                $(this).executeCommand({
                                successCallBack:function(result){
                                    valEl.val(result.FileInfo);
                                    img.attr("src", result.FileInfo.FilePath);
                                    alert(result.FileInfo);
                                },errorCallback:function(){
                                    alert("上传失败！");
                                }},"DownloadWxFile",{ServerId:serverId});
                            }
                        });
                }
            });
        }
    </script>
</body>
</html>
